package com.renren.api.connect.android.photos;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.renren.api.connect.android.Util;
import com.renren.api.connect.android.common.ResponseBean;

public class PhotoGetResponseBean extends ResponseBean {

	private List<PhotoBean> photos = new ArrayList<PhotoBean>();

	public PhotoGetResponseBean() {
		super(null);
	}
	
	public PhotoGetResponseBean(String response) {
		this(response, "json");
	}

	/**
	 * 构造函数，通过请求返回的字符串构造返回对象
	 * 
	 * @param response
	 * @param format
	 */
	public PhotoGetResponseBean(String response, String format) {
		super(response);

		if (response == null) {
			return;
		}

		SimpleDateFormat sdf = new SimpleDateFormat("yy-MM-dd HH:mm:ss");

		if (format.toLowerCase().endsWith("json")) {
			try {
				JSONArray array = new JSONArray(response);
				int size = array.length();
				JSONObject object = null;
				for (int i = 0; i < size; i++) {
					object = array.optJSONObject(i);
					if (object != null) {
						PhotoBean photo = new PhotoBean();
						photo.setUrlTiny(object.optString("url_tiny"));
						photo.setUrlHead(object.optString("url_head"));
						photo.setUrlLarge(object.optString("url_large"));
						photo.setUrlMain(object.optString("url_main"));
//						album.setCommentCount(object.optInt("comment_count"));
//						album.setUid(object.optLong("uid"));
//						album.setVisible(AlbumPrivacyType.parse(object
//								.optInt("visible")));
//						album.setUpdateTime(sdf.parse(object
//								.optString("update_time")));
//						album.setCreateTime(sdf.parse(object
//								.optString("create_time")));
//						album.setLocation(object.optString("location"));
//						album.setDescription(object.optString("description"));
//						album.setName(object.optString("name"));
//
//						album.setAid(object.optLong("aid"));
//						album.setType(AlbumType.parse(object.optInt("type")));
//						album.setUrl(object.optString("url"));
//						album.setSize(object.optInt("size"));
						
						photos.add(photo);
					}
				}
			} catch (JSONException e) {
				Util.logger("exception in parsing json data: " + e.getMessage());
			}
		}

	}
	
	public List<PhotoBean> getPhotos() {
		return photos;
	}
}
